home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT06.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.8 KB  |  117 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0                     
  4.                              Demonstration Program 6                          
  5.                                                                               
  6.  Draws lines of different colours, then fades the colours in and out          
  7.  in various ways.                                                             
  8.                                                                               
  9.  *** PROJECT ***                                                             
  10.  This program requires the file WGT5_WC.LIB to be linked.
  11.                                                                               
  12.  *** DATA FILES ***                                                          
  13.  NONE                                                                        
  14.                                                            WATCOM C++ VERSION 
  15. ==============================================================================
  16. */
  17.  
  18. #include <wgt5.h>
  19.  
  20.  
  21. void main(void)
  22. {
  23.   short y;
  24.   short oldmode;
  25.   color palette[256];
  26.   color blackpalette[256];        /* All value will be set to 0... */
  27.   color temppal[256];             /* Another black palette */
  28.  
  29.   printf ("WGT Example #6\n\n");
  30.   printf ("This program will draw an image on a black screen, fade it in slowly,\n");
  31.   printf ("then fade it out. A new screen will fade in, and then it will fade out\n");
  32.   printf ("in various portions at a time. The last screen will fade in while lines\n");
  33.   printf ("are being drawn, and then fade out while lines are being drawn.\n");
  34.   printf ("No keypresses are required once the program starts.\n");
  35.   printf ("\n\nPress any key to continue.\n");
  36.   getch ();
  37.  
  38.   if ( !vgadetected () )
  39.   {
  40.     printf("Error - VGA card required for any WGT program.\n");
  41.     exit (0);
  42.   }
  43.  
  44.   oldmode = wgetmode ();
  45.   vga256 ();
  46.   
  47.   for (y = 0; y < 256; y++)
  48.     wsetrgb (y, 0, 0, 0, blackpalette);
  49.  
  50.   wsetpalette (0, 255, blackpalette); /* Hide all colours while we draw */
  51.  
  52.   /* Now let's make a screen while all the colours are black. */
  53.   wcls (0);
  54.   for (y = 0; y < 500; y++)
  55.   {
  56.     wsetcolor (rand() % 256);
  57.     wline (rand() % 320, rand() % 200, rand() % 320, rand() % 200);
  58.   }
  59.  
  60.   /* Make a palette with some colours. */
  61.   for (y = 0; y < 64; y++)
  62.     wsetrgb (y, y, y, y, palette);
  63.   for (y = 0; y < 64; y++)
  64.     wsetrgb (y + 64, y, 0, 0, palette);
  65.   for (y = 0; y < 64; y++)
  66.     wsetrgb (y + 128, 0, y, 0, palette);
  67.   for (y = 0; y < 64; y++)
  68.     wsetrgb (y + 192, 0, 0, y, palette);
  69.  
  70.   /* Fade in the screen */
  71.   wfade_in (1, 255, 20, palette);
  72.   delay (1000);
  73.  
  74.   wfade_out (0, 255, 20, palette);
  75.  
  76.   /* Draw a new screen */
  77.   wcls (0);
  78.   for (y = 0; y < 320; y++)
  79.   {
  80.     wsetcolor (y % 200);
  81.     wline (319 - y, 0, 319, (float)y / 320.0 * 200);
  82.     wline (0, (float)y / 320.0 * 200, 319 - y, 199);
  83.   }
  84.  
  85.   wfade_in (1, 200, 40, palette);
  86.   delay (2000);
  87.  
  88.   wfade_out (1, 50, 10, palette);
  89.   wfade_out (50, 75, 10, palette);
  90.   wfade_out (75, 100, 10, palette);
  91.   wfade_out (100, 125, 10, palette);
  92.   wfade_out (125, 150, 10, palette);
  93.   wfade_out (150, 175, 10, palette);
  94.   wfade_out (175, 200, 10, palette);
  95.  
  96.   for (y = 0; y < 64; y++)
  97.   {
  98.     wline (rand() % 319, rand() % 199, rand() % 319, rand() % 199);
  99.     wfade_in_once (1, 200, palette, temppal);
  100.     wsetpalette (1, 255, temppal);
  101.     delay (30);
  102.     /* Fade in while drawing lines. */
  103.   }
  104.  
  105.   delay (2000);
  106.   for (y = 0; y < 64; y++)
  107.   {
  108.     wline (rand () % 319, rand () % 199, rand () % 319, rand () % 199);
  109.     wfade_out_once (1, 200, palette);
  110.     wsetpalette (1, 255, palette);
  111.     delay (30);
  112.     /* Fade out while drawing lines. */
  113.   }
  114.  
  115.   wsetmode (oldmode);
  116. }
  117.